class LoginController < ApplicationController
  layout "login"
  def register
   if request.post?
      user=User.new(params[:user])
      begin
        user.save!
      rescue ActiveRecord::RecordNotSaved
        notice("用户创建失败！")
      end
      redirect_to_login
    end     
  end

  def index
    if request.post?
      user =User.authenticate(params[:email],params[:password])
      if user
        session[:user_id]=user.id
        uri=session[:last_uri] #save the last uri before login
        session[:last_uri]=nil
        redirect_to(uri ||{:controller=>"manage_user",:action=>"user_info_index"})
      else
        notice("用户不存在或者密码错误！")
      end
    end
  end

  def logout
    session[:user_id]=nil
    redirect_to_login
  end
end
